package edu.dgut.networkengin2018_2.wechat_mall.util;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ResourceUtils;

import java.io.*;

/**
 * 获取阿里云oss的key word
 */
public class AliyunAccessKey {
    private String accessKeyId;
    private String accessKeySecret;

    public AliyunAccessKey() {
//        Reader reader = null;
        InputStreamReader inputStreamReader=null;
        CSVParser parser=null;
        CSVFormat csvFormat= CSVFormat.RFC4180;
        try {

            // 服务器路径
//            reader = new FileReader("/home/voghost/someServer/messages/other/AccessKey.csv");
            //本地测试路径
//            reader = new FileReader("src/main/resources/other/AccessKey.csv");
            //通用
            ClassPathResource classPathResource =new ClassPathResource("other/AccessKey.csv");
            InputStream fileStream = classPathResource.getInputStream();
            inputStreamReader = new InputStreamReader(fileStream,"UTF-8");




        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        Iterable<CSVRecord> records = null;
        try {
            records = CSVFormat.RFC4180.parse(inputStreamReader);
        } catch (IOException e) {
            e.printStackTrace();
        }
        for (CSVRecord record : records) {
            this.accessKeyId = record.get(0);
            this.accessKeySecret = record.get(1);
        }


    }

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }
}
